package cn.hanyx.coder.design.pattern.creational.factory.method.demo02;

import cn.hanyx.coder.design.pattern.creational.factory.method.demo01.factory.*;

import java.util.HashMap;
import java.util.Map;

/**
 * RuleConfigParserFactoryMap
 *
 * @author hanyx
 * @date 2020/07/14
 */
public class RuleConfigParserFactoryMap {
    private static final Map<String, IRuleConfigParserFactory> factory = new HashMap<>();

    static {
        factory.put("json", new JsonRuleConfigParserFactory());
        factory.put("xml", new XmlRuleConfigParserFactory());
        factory.put("yaml", new YamlRuleConfigParserFactory());
        factory.put("properties", new PropertiesRuleConfigParserFactory());
    }

    public static IRuleConfigParserFactory getParserFactory(String type) {
        if (type == null || type.isEmpty()) {
            return null;
        }
        return factory.get(factory);
    }
}
